package action;

import entity.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 石小俊
 * @date 2024年03月30日 14:44
 */
public class UserAction {

    public String register(HttpServletRequest request, HttpServletResponse response) {
        String username = request.getParameter("username");
        if ("admin".equals(username)) {
            request.setAttribute("registerMsg", "该用户已经被注册");
            return "fail";
        }
        return "success";
    }

    public String login(HttpServletRequest request, HttpServletResponse response) {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        if ("admin".equals(username) && "123456".equals(password)) {
            User user = new User(1, "admin", "123456", "13812345678", "江苏-南京");
            request.getSession().setAttribute("user", user);
            return "success";
        }
        request.setAttribute("loginMsg", "用户名或密码错误");
        return "fail";
    }

}
